var app = getApp();

Page({
  data: {
    p: 1,
    refundlist: [],
    isPullDown: false,
    isPullUp: false,
    isLoading: false,
    isPullUpText: ''
  },
  onLoad: function (options) {
    var that = this;
    that.getList();
  },
  onPullDownRefresh: function () {
    var that = this;
    if (that.data.isPullUp || that.data.isPullDown) {
      return
    }
    that.setData({
      p: 1,
      refundlist: [],
      isPullDown: true,
      isPullUp: false,
      isLoading: false,
      isPullUpText: ''
    });
    that.getList();
    wx.stopPullDownRefresh();
  },
  onReachBottom: function () {
    var that = this;
    if (that.data.isPullUp || that.data.isPullDown) {
      return
    }
    that.setData({
      isPullUp: false,
      isPullDown: true,
      isLoading: true
    })
    that.getList();
  },
  getList: function () {
    var that = this;
    app.JsonPost("Api/Money/refund", {
      p: that.data.p
    }, function (res) {
      if (res.list.length > 0) {
        var l = that.data.refundlist;
        for (var i = 0; i < res.list.length; i++) {
          res.list[i]["add_time"] = app.formatTime(res.list[i]["add_time"], 'Y-M-D h:m');
          l.push(res.list[i]);
        }
        that.setData({
          refundlist: l,
          p: that.data.p + 1,
          isPullUp: false,
          isPullDown: false,
          isPullUpText: '上拉加载更多',
        });
      } else {
        that.setData({
          isPullUp: false,
          isPullDown: false,
          isPullUpText: '没有更多数据了'
        });
      }
    });
  }
})